package com.atguigu.gmallre.mock.stage;

import com.atguigu.gmallre.mock.bean.UserInfo;
import com.atguigu.gmallre.mock.factory.UserSession;
import com.atguigu.gmallre.mock.log.AppCommon;
import com.atguigu.gmallre.mock.log.AppMain;
import com.atguigu.gmallre.mock.log.AppPage;
import com.atguigu.gmallre.mock.log.enums.ItemType;
import com.atguigu.gmallre.mock.log.enums.PageId;
import com.atguigu.gmallre.mock.service.LogService;
import com.atguigu.gmallre.mock.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component("register")
public class RegisterStage implements Stage{
    @Autowired
    LogService logService;

    @Autowired
    UserInfoService userInfoService;

    @Override
    public boolean handle() {
        return false;
    }

    public void register(AppMain lastPageMain){

        lastPageMain.setTs(UserSession.getCurDateTime().getTime());
        UserSession.setLastPageId(lastPageMain.getPage().getPage_id());
        logService.doLog(lastPageMain);
        AppCommon appCommon = lastPageMain.getCommon();

        UserInfo userInfo   = userInfoService. genUserInfo() ;

        UserSession.setUserInfo(userInfo);
        appCommon.setUid(userInfo.getId()+"");


        UserSession.addTimeByDuringTime(15000);

        AppPage registerPage = AppPage.builder().last_page_id(lastPageMain.getPage().getPage_id())
                .page_id(PageId.register).during_time(15000)
                .item_type(ItemType.user_id).item(userInfo.getId() + "").build();

        AppMain registerMain = AppMain.builder().common(UserSession.getAppCommon()).page(registerPage).ts(UserSession.getCurDateTime().getTime()).build();
        logService.doLog(registerMain);

        UserSession.addTimeByDuringTime(lastPageMain.getPage().getDuring_time());
        lastPageMain.setTs(UserSession.getCurDateTime().getTime());

        lastPageMain.getPage().setLast_page_id(PageId.register);
        lastPageMain.getPage().setFrom_pos_id(null);
        lastPageMain.getPage().setFrom_pos_seq(null);
        lastPageMain.getPage().setRefer_id(null);



    }
}
